<%@ page pageEncoding="UTF-8"%>
<%@ include file="../common/tag.jsp"%>
<div style="margin: 8px 0;">
	<input type="button" class="btn btn-info btn-add" value="新增" url="${ctx}/category?opt=add">
</div>
<table class="table table-bordered">
	<thead>
		<tr>
			<th>类目名称</th>
			<th>图片</th>
			<th>参数</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${list}" var="item">
			<tr>
				<td>${item.name }</td>
				<td>${item.icon }</td>
				<td>${item.param }</td>
				<td>
					<button class="btn btn-warning btn-xs btn-update" url="${ctx}/category?opt=update&id=${item.id}">修改</button>
					<button class="btn btn-danger btn-xs btn-del" url="${ctx}/category?opt=delete&id=${item.id}">删除</button>
				</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
<script>
//弹出
$('.btn-add').click(function() {
	layer.open({
		title : '新增',
		maxmin: true,
		type : 2,
		area : ['800px', '600px'],
		content : $(this).attr('url')
	});
})

//弹出
$('.btn-update').click(function() {
	layer.open({
		title : '修改',
		maxmin: true,
		type : 2,
		area : ['800px', '600px'],
		content : $(this).attr('url')
	});
})

//删除
$('.btn-del').click(function() {
	var url = $(this).attr('url');
	layer.confirm('确认删除该信息?', function(index) {
		layer.close(index);
		//异步删除
		$.ajax({
			url : url,
			dataType : 'json',
			success : function(data) {
				layer.alert(data.msg, function(index_) {
					//刷新列表的内容
					$('.load-data').click();
					layer.close(index_);
				});
			}
		});
	});
});
</script>
